package com.example.home.rubbish.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.rubbish.bean.NewsClassifyDetail;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class ClassifyDetailAdapter extends RecyclerView.Adapter<ClassifyDetailAdapter.MyHoldy> {
    private Context context;
    private List<NewsClassifyDetail.RowsBean> list;

    public ClassifyDetailAdapter(Context context, List<NewsClassifyDetail.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ClassifyDetailAdapter.MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_clas, null);
        return new ClassifyDetailAdapter.MyHoldy(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ClassifyDetailAdapter.MyHoldy holder, int position) {

        Glide.with(context).load(ip+list.get(position).getImgUrl()).into(holder.imgUrl);
        holder.introduce.setText(list.get(position).getIntroduce());
        holder.guide.setText(list.get(position).getGuide());
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyHoldy extends RecyclerView.ViewHolder {
        private ImageView imgUrl;
        private TextView introduce;
        private TextView guide;

        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            imgUrl = itemView.findViewById(R.id.imgUrl);
            introduce = itemView.findViewById(R.id.introduce);
            guide = itemView.findViewById(R.id.guide);
        }
    }
}
